;
(function() {
  'use strict';
  angular.module('services.dataQualityMng')
    .service('businessFluctuationAlarmService', BusinessFluctuationAlarmService);

  function BusinessFluctuationAlarmService($filter, Restangular) {
    return {
      fmtTitle: fmtTitle,
      alarmTypes:alarmTypes,
      fmtSendData: fmtSendData,
      businessQuery: businessQuery
    };

    function businessQuery(params, callback) {
      Restangular.all('sas/dataManager/dataQuality/dataMonitor/businessFluctuation/query').post(params).then(callback);
    }

    function alarmTypes() {
      var alarmTypes = [{
        alarmTypeCode: '1',
        alarmTypeName: '数据完整性'
      }, {
        alarmTypeCode: '2',
        alarmTypeName: '数据准确性'
      }, {
        alarmTypeCode: '3',
        alarmTypeName: '数据时效性'
      }];
      return alarmTypes;
    }

    function fmtSendData(send, businessLineName, alarmTypes) {
      var sendData = {
        date: $filter('date')(send.date, 'yyyy-MM-dd'),
        businessCodes: [],
        alarmTypeCodes: [],
        page: {
          currentPage: send.currentPage,
          pageSize: send.pageSize
        }
      }
      if (send.businessCodes === 0) {
        sendData.businessCodes = businessLineName.map(function(bn) {
          return bn.businessLineCode;
        });
      } else {
        sendData.businessCodes.push(send.businessCodes.businessLineCode);
      }

      if (send.alarmTypeCodes === 0) {
        sendData.alarmTypeCodes = alarmTypes.map(function(bn) {
          return bn.alarmTypeCode;
        });
      } else {
        sendData.alarmTypeCodes.push(send.alarmTypeCodes.alarmTypeCode);
      }
      return sendData;
    };

    function fmtTitle(time, businessCodes) {
      var title = '';
      if (businessCodes === 0) {
        title = time + '统一支付系统业务数据处理告警分析';
      } else {
        title = time + businessCodes.businessLineName + '业务数据处理告警分析';
      }
      return title;
    };
  }
})();